package com.example.ceramics.activity;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.View;
import android.widget.ImageView;

import com.example.ceramics.R;
import com.example.ceramics.adapter.GoodsAdapter;
import com.example.ceramics.database.dao.GoodsDaoImpl;
import com.example.ceramics.database.dao.IGoodsDao;
import com.example.ceramics.entity.GoodsEntity;
import com.example.ceramics.data.Datas;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class ServiceActivity extends BaseActivity {

    private ImageView ivReturn;
    private RecyclerView recyclerView;
    private GoodsAdapter goodsAdapter;

    private List<List<String>> Names = new ArrayList<>();
    private List<List<Double>> Prices = new ArrayList<>();
    private List<List<String>> Signatures = new ArrayList<>();
    private List<List<Integer>> Imgs = new ArrayList<>();
    private List<String> type;

    private Datas datas=new Datas();

    private IGoodsDao goodsDao;

    @Override
    protected int initLayout() {
        return R.layout.activity_service;
    }

    @Override
    protected void initView() {
        ivReturn = findViewById(R.id.iv_return);
//        recyclerView = findViewById(R.id.recyclerView);
    }

    @Override
    protected void initData() {
//        data();
        ivReturn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

//        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 2);
//        recyclerView.setLayoutManager(gridLayoutManager);
//
//        localGoodsList();
    }

    private void localGoodsList() {
        goodsDao  =new GoodsDaoImpl(this);
        List<GoodsEntity> list = new ArrayList<>();
        list=goodsDao.listGoodsByType("定制服务");
//        for (int i = 0; i < Names.get(7).size(); i++) {
//            GoodsEntity goodsEntity = new GoodsEntity();
//            goodsEntity.setGoodsName(Names.get(7).get(i));
//            goodsEntity.setGoodsPrice(Prices.get(7).get(i));
//            goodsEntity.setGoodsSignature(Signatures.get(7).get(i));
//            goodsEntity.setGoodsType("定制服务");
//            goodsEntity.setGoodsImg(Imgs.get(7).get(i));
//            list.add(goodsEntity);
//        }
        goodsAdapter = new GoodsAdapter(this,list);
        recyclerView.setAdapter(goodsAdapter);
        goodsAdapter.setOnItemClickListener(new GoodsAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(Serializable obj) {
                GoodsEntity goodsEntity = (GoodsEntity)obj;
                navigateTo(DetailActivity.class, "detail", goodsEntity);
            }
        });
    }

    private void data() {
        datas.setDatas();
        Names = datas.getNames();
        Prices = datas.getPrices();
        Signatures = datas.getSignatures();
        Imgs = datas.getImgs();
        type = datas.getType();
    }
}